<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册登录界</title>
    <link rel="stylesheet" href="./style.css" >
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js'></script>
    <script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
  <div class="container">
    <div class="welcome">
      <div class="pinkbox">
        <div class="signup nodisplay">
          <h1>注   册</h1>
          <form autocomplete="off">
            <input type="email" placeholder="邮箱"  required="required" id="email">
            <input type="text" placeholder="验证码" required="required" id="verify">
            <input type="text" placeholder="用户名" required="required" id="cusername">
            <input type="password" placeholder="密码" required="required" id="cpassword">
            <input type="password" placeholder="确认密码" required="required" id="cqpassword">
            <input type="text" placeholder="密保问题：你父母的名字 " required="required" id="answer">  
            <button id="yanzheng" >获取</button>
            <button class="button submit" id="create" type="button">创建</button>
          </form>
        </div>
        <div class="signin">
          <h1>登 录</h1>
          <form class="more-padding" autocomplete="off">
            <input type="text" placeholder="用户名" required="required" id="username" >
            <input type="password" placeholder="密码" required="required" id="password">
            <a href="forget.html" id="forget">忘记密码</a>
            <button class="buttom sumbit" type="button">登录</button>
          </form>
        </div>
      </div>

      <div class="leftbox">
        <h2 class="title"><span>DESIGNED</span>by<br>YUNTENG</h2>
        <img class="flower smaller" src="1.png" /><br>
        <p class="account">已经有一个账户?</p>
        <button class="button" id="signin">登录</button>
      </div>

      <div class="rightbox">
        <h2 class="title"><span>DESIGNED</span>by<br>YUNTENG</h2>
        <img class="flower" src="1.png" /><br>
        <p class="account">还没有一个账户?</p>
        <button class="button" id="signup">创建</button>
      </div>
    </div>
  </div>
  <script>
    $('#signup').click(function() {
    $('.pinkbox').css('transform', 'translateX(80%)');
    $('.signin').addClass('nodisplay');
    $('.signup').removeClass('nodisplay');
    });

    $('#signin').click(function() {
      $('.pinkbox').css('transform', 'translateX(0%)');
      $('.signup').addClass('nodisplay');
      $('.signin').removeClass('nodisplay');
    });
    //获取输入的值
    var forget = document.getElementById('forget')
    const btns = document.querySelectorAll('button')
    var childStr = document.getElementById("cusername").value
    var childStr = document.getElementById("cpassword").value
    var childStr = document.getElementById("cqpassword").value   
    var childStr = document.getElementById("verify").value
    var childStr = document.getElementById("answer").value
    var childStr = document.getElementById("username").value
    var childStr = document.getElementById("password").value
    var childStr = document.getElementById("email").value
    var cd;
    var uname
    //验证吗
    btns[0].onclick = function(){
    axios.post(
      'http://yuntenglibrary.natapp1.cc/register',
      {
        emailBox:email.value
      }).then(response =>{
        console.log(response)
        cd = response.data.cd
      })
    }
    //创建
    btns[1].onclick = function(){
      if(cd !=null){
      if (verify.value == cd) {
        console.log("验证码正确")
      }
      else{
        alert("验证码错误")
      }
      // alert(cusername.value)
      // alert(cpassword.value)
      axios.post(
        'http://yuntenglibrary.natapp1.cc/register01',
        {
            userName:cusername.value,
            password:cpassword.value,
            encrypted:answer.value,
            emailBox:email.value
        }).then(response =>{
          console.log(response)
          if (response.data.code == 1) {
            //用户丹姐
            window.location = "../新主页填充版/index.html"
          }
        })
      }
    }
    //登录
    btns[2].onclick = function(){
      // alert(username.value)
      axios.post(
        'http://yuntenglibrary.natapp1.cc/login',
        {
            password:password.value,
            userName:username.value
        }).then(response =>{
          console.log(response)
          //alert(response.data.status)
          //alert(response.data.code)
          uname = username.value
          //alert(uname)
          if (response.data.code == 1) {
            //用户丹姐
            window.location="../新主页填充版/index.html";
          }
          if (response.data.code == -2) {
            alert("The password does not match the userName")
          }
          if (response.data.code == -1) {
            alert("没有该用户")
          }
          if (response.data.code == 2) {
            //管理员元俊洋
            window.location = "../管理员界面/pageAdm.html" ;
          }
        })
    }
    //去登陆 
    btns[3].onclick = function(){

    }
    //去创建
    btns[4].onclick = function(){

    }
    //忘记密码页面跳转
    forget.onclick = function(){

    }
  </script>
</body>
</html>